import {Button, Flex} from "antd";
import CommonModel from "@/components/common/CommonModel";
import React, {useRef, forwardRef, useImperativeHandle} from "react";
interface IModelRef {
    showModal: () => void
    handleCancel: (cb?: () => void) => void
    handleOk: (cb?: () => void) => void
}

interface IProps {
    selectDel: () => void
    btn: React.ReactNode
}

const BatchDel = forwardRef(({ selectDel, btn }: IProps, ref) => {
    const modalRef = useRef(null)
    const handleCancel = () => {
        // eslint-disable-next-line @typescript-eslint/no-unused-expressions
        modalRef.current && (modalRef.current as IModelRef).handleCancel()
    }
    const showModal = () => {
        // eslint-disable-next-line @typescript-eslint/no-unused-expressions
        modalRef.current && (modalRef.current as IModelRef).showModal()
    }
    const handleOk = () => {
        // eslint-disable-next-line @typescript-eslint/no-unused-expressions
        modalRef.current && (modalRef.current as IModelRef).handleOk(() => {
            selectDel()
        })
    }
    useImperativeHandle(ref, () => ({
        showModal: showModal
    }))
    return (
        <CommonModel
            close={handleCancel}
            footer={
                <Flex gap='middle' wrap justify='end'>
                    <Button onClick={handleCancel}>取消</Button>
                    <Button type='primary' onClick={handleOk}>确定</Button>
                </Flex>
            }
            ref={modalRef}
            title={'温馨提示'}
            btn={btn}
            content={<div style={{ textAlign: 'center' }}>删除后不可恢复，您确定删除已选文件？</div>}
        />
    )
})

export default BatchDel